package com.company.clientscard.server.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.company.clientscard.server.dao.GeneralDao;
import com.company.clientscard.server.domain.User;

public class UserService {
	private GeneralDao dao;

	@Required
	public void setDao(GeneralDao dao) {
		this.dao = dao;
	}

	@Transactional(readOnly = true)
	public User findById(Long id) {
		return (User) dao.findById(User.class, id);
	}

	@Transactional
	public void save(User object) {
		dao.save(object);
	}

	@Transactional
	public User update(User object) {
		dao.update(object);
		return (User) dao.findById(object.getClass(), object.getId());
	}

	@Transactional(readOnly = true)
	public List<User> findAll(Class<User> clazz) {
		return dao.findAll(clazz);
	}

	@Transactional(readOnly = true)
	public List<User> findAll(Class<User> clazz, int firstRow, int numberOfRows) {
		return dao.findAll(clazz, firstRow, numberOfRows);
	}
}
